import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		/* 登录状态 */
		token: uni.getStorageSync('token') || null,
		userInfo: null,
		userId: uni.getStorageSync('userId') || null,
		balanceObj: null,
		tabActive: 0,
	},
	mutations: {
		LOGIN(state, token) {
			state.token = token;
			uni.setStorageSync('token', token);
		},
		USERID(state, opt) {
			state.userId = opt;
			uni.setStorageSync('USERID', opt);
		},
		UPDATE_LOGIN(state, token) {
			state.token = token;
		},
		LOGOUT(state) {
			state.token = undefined;
			state.uid = undefined
			uni.clearStorageSync('token');
			uni.clearStorageSync('UID');
		},
		UPDATE_USERINFO(state, userInfo) {
			state.userInfo = userInfo;
			uni.setStorageSync('USERINFO', userInfo);
		},
		UPDATE_BALANCEOBJ(state, balanceObj) {
			state.balanceObj = balanceObj;
			uni.setStorageSync('BALANCEOBJ', balanceObj);
		},
	}
})

export default store
